/*
 * This file (Random.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */
package org.algoristes.alkwarel.utils;

import java.util.Random;

/**
 * @author Xavier Gouchet
 * 
 */
public class Rand {

	private static Rand RANDOM_GENERATOR;
	protected Random mRandom;

	private Rand() {
		mRandom = new Random();
	}

	private static Rand getRandom() {
		if (RANDOM_GENERATOR == null)
			RANDOM_GENERATOR = new Rand();
		return RANDOM_GENERATOR;
	}

	/**
	 * @return a random double value between 0 (inclusive) and 1 (exclusive)
	 */
	public static double getDouble() {
		return getRandom().mRandom.nextDouble();
	}

	/**
	 * @param d
	 * @return a random double value between 0 (inclusive) and d (exclusive)
	 */
	public static double getDouble(double d) {
		return (getRandom().mRandom.nextDouble() * d);
	}

	/**
	 * @param min
	 * @param max
	 * @return a random double value between min (inclusive) and max (exclusive)
	 */
	public static double getDouble(double min, double max) {
		return ((getRandom().mRandom.nextDouble() * (max - min)) + min);
	}

}
